package remoteService;

import gui.*;
import concole.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

import javax.swing.*;

import org.omg.PortableInterceptor.ObjectIdHelper;

public class Client extends LoginEntry {
	private final String STUDENTFILE = "studentsList.txt";
	private final String TEACHERFILE = "teachersList.txt";
	private final String COURSEFILE = "courseList.txt";
	private final String COURSESELECTEDFILE = "courseSelected.txt";
	private final String STUDENTACCOUNTSFILE = "studentAccounts.txt";
	private final String TEACHERACCOUNTSFILE = "teacherAccounts.txt";
	private DataInputStream fromServer;
	private DataOutputStream toServer;
	private ObjectInputStream objectFromServer;
	private ObjectOutputStream objectToServer;
	private Socket socket;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Client();
	}

	public Client() {
		super();
		try {

			socket = new Socket("localhost", 8000);
			// System.out.print(toServer);
			// objectFromServer = new
			// ObjectInputStream(socket.getInputStream());
			// objectToServer = new
			// ObjectOutputStream(socket.getOutputStream());
			// fromServer = new DataInputStream(socket.getInputStream());
			// toServer = new DataOutputStream(socket.getOutputStream());
			PrintWriter pw = getWriter(socket);
		} catch (IOException ex) {
			System.out.println(ex);
		}
	}

	public boolean checkCompitabel(User user) {
		boolean isCompitable = true;

		System.out.println("som");
		try {
			// toServer.writeBytes("Login");
			// objectToServer.writeObject(user);
			toServer.writeBytes(user.toCheckString());
		} catch (IOException e) {
			System.err.println(e);
		}
		return isCompitable;
	}

	public boolean checkExitence(User user) {
		boolean isExistened = false;
		System.out.println(user + " ");
		return isExistened;
	}

	public PrintWriter getWriter(Socket socket) throws IOException {
		OutputStream socketOut = socket.getOutputStream();
		return new PrintWriter(socketOut, true);
	}

}
